package com.xindacloud.sms.portal.utils;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.HashMap;
import java.util.Map;

public class MappingStatusHelp {


    public enum NexmoMessageStatus {
        OK(0, 10000, "该SMS已成功接受传递"),
        THROTTLED(1, 10001, "发送SMS的速度超出帐户限制"),
        MISSING_PARAMS(2, 10002, "请求缺少必要的参数之一：from，to，api_key，api_secret或text"),
        INVALID_PARAMS(3, 10003, "一个或多个参数的值无效"),
        INVALID_CREDENTIALS(4, 10004, "您的API密钥和/或机密不正确，无效或被禁用"),
        INTERNAL_ERROR(5, 10005, "处理此消息时平台中发生了错误"),
        INVALID_MESSAGE(6, 10006, "平台无法处理此消息，例如，无法识别的数字前缀"),
        NUMBER_BARRED(7, 10007, "您尝试向其发送消息的号码已列入黑名单，可能不会收到。"),
        PARTNER_ACCOUNT_BARRED(8, 10008, "禁止合作伙伴帐户"),
        PARTNER_QUOTA_EXCEEDED(9, 10009, "您没有足够的信用来发送消息。充值并重试"),
        TOO_MANY_BINDS(10, 10010, "与平台的同时连接数超出了您的帐户分配"),
        ACCOUNT_NOT_HTTP(11, 10011, "帐户未启用HTTP"),
        MESSAGE_TOO_LONG(12, 10012, "消息长度超过了允许的最大长度"),
        COMMS_FAILURE(13, 10013, ""),
        INVALID_SIGNATURE(14, 10014, "提供的签名无法验证"),
        INVALID_FROM_ADDRESS(15, 10015, "发件人地址无效"),
        INVALID_TTL(16, 10016, "无效的TTL"),
        NUMBER_UNREACHABLE(17, 10017, ""),
        TOO_MANY_DESTINATIONS(18, 10018, ""),
        FACILITY_NOT_ALLOWED(19, 10019, ""), INVALID_MESSAGE_CLASS(20, 10020, ""), UNKNOWN(Integer.MAX_VALUE, 99999, "未知异常");

        private int messageStatus;

        private int mappingCode;

        private String messageDesc;

        private static final Map<Integer, NexmoMessageStatus> MESSAGE_STATUS_INDEX = new HashMap<>();

        static {
            for (NexmoMessageStatus messageStatus : NexmoMessageStatus.values()) {
                MESSAGE_STATUS_INDEX.put(messageStatus.messageStatus, messageStatus);
            }
        }

        NexmoMessageStatus(int messageStatus, int mappingCode, String messageDesc) {
            this.messageDesc = messageDesc;
            this.messageStatus = messageStatus;
            this.mappingCode = mappingCode;
        }

        @JsonCreator
        public static NexmoMessageStatus fromInt(int messageStatus) {
            NexmoMessageStatus foundStatus = MESSAGE_STATUS_INDEX.get(messageStatus);
            return (foundStatus != null) ? foundStatus : UNKNOWN;
        }

        public int getMessageStatus() {
            return messageStatus;
        }

        public NexmoMessageStatus setMessageStatus(int messageStatus) {
            this.messageStatus = messageStatus;
            return this;
        }

        public int getMappingCode() {
            return mappingCode;
        }

        public NexmoMessageStatus setMappingCode(int mappingCode) {
            this.mappingCode = mappingCode;
            return this;
        }

        public String getMessageDesc() {
            return messageDesc;
        }

        public NexmoMessageStatus setMessageDesc(String messageDesc) {
            this.messageDesc = messageDesc;
            return this;
        }
    }

    public enum CmMessageStatus{
        ACCEPTED(0,10000," 运营商已接受"),
        REJECTED(1,10001,"被平台拒绝或者被运营商拒绝"),
        DELIVERED(2,10002,"已交付"),
        FAILED(3,10003,"消息不规范不会被发送"),
        READ(4,10004,"不用于短信，仅用于其他渠道"),
        UNKNOWN(Integer.MAX_VALUE, 99999, "未知异常");

        private int messageStatus;

        private int mappingCode;

        private String messageDesc;

        private static final Map<Integer, CmMessageStatus> MESSAGE_STATUS_INDEX = new HashMap<>();

        static {
            for (CmMessageStatus messageStatus : CmMessageStatus.values()) {
                MESSAGE_STATUS_INDEX.put(messageStatus.messageStatus, messageStatus);
            }
        }

        CmMessageStatus(int messageStatus, int mappingCode, String messageDesc) {
            this.messageDesc = messageDesc;
            this.messageStatus = messageStatus;
            this.mappingCode = mappingCode;
        }

        @JsonCreator
        public static CmMessageStatus fromInt(int messageStatus) {
            CmMessageStatus foundStatus = MESSAGE_STATUS_INDEX.get(messageStatus);
            return (foundStatus != null) ? foundStatus : UNKNOWN;
        }

        public int getMessageStatus() {
            return messageStatus;
        }

        public CmMessageStatus setMessageStatus(int messageStatus) {
            this.messageStatus = messageStatus;
            return this;
        }

        public int getMappingCode() {
            return mappingCode;
        }

        public CmMessageStatus setMappingCode(int mappingCode) {
            this.mappingCode = mappingCode;
            return this;
        }

        public String getMessageDesc() {
            return messageDesc;
        }

        public CmMessageStatus setMessageDesc(String messageDesc) {
            this.messageDesc = messageDesc;
            return this;
        }

    }

}
